package com.speech.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import com.ontbee.legacyforks.cn.pedant.SweetAlert.SweetAlertDialog;
import com.speech.R;
import com.speech.net.BasicCallBack;
//import com.speech.net.HttpCommunicationManager;
import com.speech.net.constant.EnumReqestActionCode;
import com.speech.net.entity.MessageC2S;
import com.speech.net.entity.MessageC2SBuilder;
import com.speech.net.entity.MessageS2C;
import com.speech.utils.ClipBoardUtil;
import com.speech.utils.JsonProcessor;
import com.speech.utils.TitleBuilder;

public class InviteActivity extends AppCompatActivity {

    private ImageView img_btn;
    private SweetAlertDialog dialog;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_invite);
        _initView();

        img_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (ClipBoardUtil.strInviteCode == null) {
                    _get_invite_code();
                } else {
                    ClipBoardUtil.copy("", InviteActivity.this);
                    dialog = new SweetAlertDialog(InviteActivity.this, SweetAlertDialog.SUCCESS_TYPE)
                            .setTitleText("已将邀请码保存到剪切板")
                            .setConfirmText("OK");
                            dialog.show();
                }
            }
        });
    }

    private void _get_invite_code() {
        //TODO: 接口请求
//        MessageC2S msg_c2s = MessageC2SBuilder.buildGeneral_MessageC2S(InviteActivity.this, EnumReqestActionCode.获得邀请码地址, null);
//        String json = JsonProcessor.StcGetJson(msg_c2s);
//        HttpCommunicationManager.getInstance().doPost(json, new BasicCallBack(InviteActivity.this, json, new BasicCallBack.BasicCallBackListener() {
//            @Override
//            public void success(MessageS2C msg_s2c) {
//                ClipBoardUtil.strInviteCode = msg_s2c.strData.replace("{\"url\":\"", "").replace("\"}", "");
//                ClipBoardUtil.copy("", InviteActivity.this);
//                new SweetAlertDialog(InviteActivity.this, SweetAlertDialog.SUCCESS_TYPE)
//                        .setTitleText("已将邀请码保存到剪切板")
//                        .setConfirmText("OK")
//                        .show();
//            }
//            @Override
//            public void fail(MessageS2C msg_s2c) {
//                ClipBoardUtil.copy(null, InviteActivity.this);
//                new SweetAlertDialog(InviteActivity.this, SweetAlertDialog.SUCCESS_TYPE)
//                        .setTitleText("已将邀请码保存到剪切板")
//                        .setConfirmText("OK")
//                        .show();
//            }
//        }));
    }


    private void _initView() {
        new TitleBuilder(this).setTitleText("邀请好友");

        img_btn = findViewById(R.id.img_invite_btn);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (dialog != null){
            dialog.dismissWithAnimation();
        }
    }
}
